home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15080 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: global.gc.net!sourcebbs!david.mohorn
  2. From: david.mohorn@sourcebbs.com (DAVID MOHORN)
  3. Newsgroups: comp.lang.c
  4. Subject: COLLEGE PROFESSORS! # 2/2
  5. Message-ID: <8BEC555.02C70031C4.uuout@sourcebbs.com>
  6. Date: Tue, 16 Apr 96 22:45:00 -0500
  7. Distribution: world
  8. Organization: SelectiveSourceBBS VirginiaBeach  (804)471 6776
  9. Reply-To: david.mohorn@sourcebbs.com (DAVID MOHORN)
  10. X-Newsreader: PCBoard Version 15.22
  11. X-Mailer: PCBoard/UUOUT Version 1.20
  12.  
  13. (Continued from previous message)
  14.  
  15.  
  16. return StatusSwitch
  17. *** end of validation routine ***
  18.  
  19. Clearly, example 1 is inefficient and wastes processing time by
  20. continuing to check for valid data once an error is found and wasting
  21. another few CPU cycles making another comparison.
  22.  
  23. Example 2 to me seems like the best approach by returning to the caller
  24. immediately once and error if found.
  25.  
  26. Example 3 is almost as good as 2, since the nested-ifs will not continue
  27. to validate data once an error is found.
  28.  
  29. The instructors philosophy is to make it more "readable" and keep it as
  30. structured as possible!  As if structured programming was the only way
  31. to accomplish this task.  He also stated that nested ifs make the code
  32. harder to read. He also stated that there is no arm in wasting a
  33. few milliseconds doing the extra conditions, since it won't be
  34. noticeable anyway.
  35.  
  36. I retorted his remark and said it would on a multitasking system where
  37. every cycle counts!  If I were validating 10,000 data items, example 1
  38. would take a considerable amount of time longer than example 2!
  39.  
  40. Does anyone else have any opinions or horror stories?
  41.  
  42. RIME: ->1369 FIDO: (1:275/102) INTERNET: david.mohorn@sourcebbs.com
  43.  
  44. ---
  45.  * QMPro 1.53 * Programming is 10% inspiration and 90% debugging.
  46.  
  47.  
  48. ---
  49. This message originated from:  ----------        Selective Source BBS
  50.                                     -------    Virginia Beach, Virginia
  51.                                          -----      (804) 471 6776
  52.